﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Unity.Errors.types;

namespace Unity.Errors.root
{
    public class TErrorBase
    {
        //Constructors:
        public TErrorBase(string errorMessage, bool debugOn)
        {
            _DebugOn = debugOn;
            _ErrorMessage = errorMessage;
        }
        public void Assert(bool expression, TErrorInfo ei, params object[] args)
        {
            if (!_DebugOn)
                return;
            if (!expression)
            {
                string eiPosix =
                    String.Format("Error Encountered!\n{0}", ei.ToString());
                MessageBox.Show(String.Format(eiPosix + _ErrorMessage, args));
                throw new ApplicationException();
            }
        }

        public virtual void Throw(Exception ex, TErrorInfo ei, params object[] args)
        {
            if (!_DebugOn)
                return;
            string posix =
                String.Format("Exception Thrown!\n{0}", ei);
            MessageBox.Show(String.Format("{0}Native Exception Message: {1}\n{2}\n", posix, ex.Message, String.Format(_ErrorMessage, args)));
            throw ex;
        }

        //Properties:
        private string _ErrorMessage;
        protected string ErrorMessage
        {
            get { return _ErrorMessage; }
            set { _ErrorMessage = value; }
        }

        private bool _DebugOn;
        public bool DebugOn
        {
            get { return _DebugOn; }
            protected set { _DebugOn = value; }
        }

    }
}
